#!/usr/bin/python
# -*-coding: UTF-8 -*-
"""
# Time: 2021/10/24 9:48
# @Author: 修养
# @Project_name: PROJECT_NAME
"""


def do():
    print("我去买东西！")


def i_buy(name, something):
    print(name, '买：', something)


def who_sell(name, something):
    print(name, '卖：', something)


def many_buy(something, weight='1 kg'):
    print(something, '买', weight)


# 函数调用
do()  # 无参
i_buy('I', '西红柿')  # 给形参传实参,且用的是位置实参
who_sell(name='张大妈', something='鸡蛋、冬瓜、蔬菜')  # 关键字实参
many_buy('西红柿')  # weight='1 kg'形参给个默认值，不传这个实参时，使用默认值
many_buy('白菜', weight='2kg')  # 位置实参，weight不使用默认值
many_buy(something='冬瓜', weight='1.5kg')  # 关键字实参，weight不使用默认值

print('~~~~~~~~~~~~~1111: 有返回值的函数~~~~~~~~~~~~~~~~~~~~')


def who_specking(name):
    speaking = f'{name} 正在说话！'
    return speaking


def teacher(name, flag=True):
    something = f'{name} 来了，是{flag}的'
    return something


def students(age, classes=None):
    """
    满足条件时：给字典添加元素
    :param age:
    :param classes:
    :return: ：返回字典
    """
    student = {'id': '0000', 'name': '陈长生'}
    if age:
        student['age'] = age
        student['门派'] = classes
    return student


result1 = who_specking('李秋水')
print(result1)
result2 = teacher('王老师')
print(result2)
result3 = students(200000, '补天阁')
print(result3)


def print_list(lists):
    """
    遍历传递的列表元素
    :param lists: 列表
    :return:
    """
    for i in lists:
        print(i)


list0 = ['武当', '少林']
print_list(list0)


def something1(*fruits):  # *fruits 相当于建了一个空元组：fruits = ()
    print(fruits)


def something2(*fruits):  # *fruits 相当于建了一个空元组：fruits = ()
    """
    传递任意数量的实参
    :param fruits:元组
    :return:
    """
    foods = []
    for fruit in fruits:
        foods.append(fruit)
    print(foods)


something1('苹果', '葡萄')
something2('苹果', '葡萄')
lists = ['苹果', '葡萄']
something2(lists)    # 把列表当做一个参数 传给 fruits元组里作为一个参数
something2()


def something3(name, *fruits):  # *fruits 相当于建了一个空元组：fruits = ()
    """
    结合使用位置实参和任意数量实参
    :param name:
    :param fruits:
    :return:
    """
    print(name, 'like', fruits)


def something4(sect, **students):  # **fruits ,两个*号相当于建了一个空字典：fruits = []
    """
    传递任意数量的关键字实参
    :param sect:
    :param students:
    :return:
    """
    students["门派"] = sect
    return students


something3('小明', '苹果', '葡萄')
students = something4("补天阁", id='0001', name="孟天正")
print(students)